using System;
using System.Collections.Generic;
using System.Text;
using SwinMessengerLibrary;

namespace SwinMessengerConsoleApp
{
    class CommandProcessor
    {
        /// <summary>
        /// This is the command processor, it handles all of the commands for the SwinMessengerConsoleApp
        /// </summary>
        public CommandProcessor()
        {
            MessageCommand msg = new MessageCommand();
            _Commands.Add(msg);
            RosterCommand roster = new RosterCommand();
            _Commands.Add(roster);
            HelpCommand help = new HelpCommand();
            _Commands.Add(help);
            QuitCommand quit = new QuitCommand();
            _Commands.Add(quit);
        }
        private List<SwinMessengerCommand> _Commands = new List<SwinMessengerCommand>();
        /// <summary>
        /// This will execute the command which the user types in
        /// </summary>
        /// <param name="runOn">the Server to execute the command on</param>
        /// <param name="input">the command to execute</param>
        /// <returns>This is the out put of the command and what the user will see</returns>
        public List<string> Execute(Server runOn, string input)
        {
            string[] tempArray = input.Split(' ');
            List<string> tempList = new List<string>();
            bool found = false;
            foreach (SwinMessengerCommand command in _Commands)
            {
                if (command.AreYou(tempArray[0])) 
                {
                    tempList = command.Execute(runOn, tempArray);
                    found = true;
                }
            }
            if (found)
            {
                return tempList;
            }
            else
            {
                tempList.Add("The command " + tempArray[0] + " cound not be found!");
                tempList.Add("Try typing help for a list of commands");
                return tempList;
            }
        }
    }
}
